package cn.wjc.demo.partone.client.fallback;

import cn.wjc.demo.common.entity.Student;
import cn.wjc.demo.partone.client.PartoneFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Slf4j
@Component //将PartoneFeignServiceFactory注册为bean
public class PartoneFeignServiceFactory implements FallbackFactory<PartoneFeignService> {

    /**
     * 默认方法
     * @param cause
     * @return
     */
    @Override
    public PartoneFeignService create(Throwable cause) {
        PartoneFeignServiceFactory.log.error("fallback; reason was: {}", cause.getMessage());
        return new PartoneFeignService() {
            @Override
            public void remoteCallParttwoDoSomething(String s) {
                log.error("FallbackFactory降级...");
                System.out.println(s);
            }

            @Override
            public void remoteCallParttwoAddStudent(Student student) {
                log.error("FallbackFactory降级,新增学生失败...");
            }
        };
    }
}
